/*********************************************************************
 * Software License Agreement
 *
 * Copyright (C) 2010 Cross The Road Electronics.  All rights
 * reserved.
 *
 * Cross The Road Electronics (CTRE) licenses to you the right to 
 * use, copy, modify, merge, publish, distribute, sublicense, and/or 
 * sell copies of the Software ONLY when in use with CTRE's 2CAN 
 * Ethernet CAN Gateway.
 *
 * THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT
 * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
 * LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
 * CROSS THE ROAD ELECTRONICS BE LIABLE FOR ANY INCIDENTAL, SPECIAL, 
 * INDIRECT OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF
 * PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS
 * BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE
 * THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER
 * SIMILAR COSTS, WHETHER ASSERTED ON THE BASIS OF CONTRACT, TORT
 * (INCLUDING NEGLIGENCE), BREACH OF WARRANTY, OR OTHERWISE.
 *
********************************************************************/
#include "OS_Task.h"

#ifdef OS_ABSTRACTION_VISUAL_STUDIO

	OS_Task::OS_Task(WEAK_CONST TCHAR * name, unsigned int (*Func)(void * lpParam), void * lpParam)
	{
		m_Func = Func;
		m_lpParam = lpParam;

		DWORD dwID;
		m_handle = CreateThread( NULL,                   // default security attributes
								0,                      // use default stack size  
								ThreadCaller,       // thread function name
								this,          // argument to thread function 
								0,                      // use default creation flags 
								&dwID);   // returns the thread identifier 
	}
	OS_Task::~OS_Task()
	{
		if(m_handle)
			CloseHandle(m_handle);
		m_handle = 0;
	}

	DWORD WINAPI OS_Task::ThreadCaller( LPVOID lpParam )
	{
		return ((OS_Task*)lpParam)->ThreadCaller();
	}

	DWORD WINAPI OS_Task::ThreadCaller()
	{
		return m_Func(m_lpParam);
	}


#endif
	

	
#if defined(OS_ABSTRACTION_VXWORKS)

#include "vxworks/Task.h"
	
	OS_Task::OS_Task(WEAK_CONST TCHAR * name, unsigned int (*Func)(void * lpParam), void * lpParam)
	{
		m_Func = Func;
		m_lpParam = lpParam;

		m_task = new CTask(name,(FUNCPTR)InitTask);
		m_task->Start((INT32)this);
	}
	void OS_Task::InitTask(OS_Task * pThis) 
	{
		pThis->Run();
	}
	void OS_Task::Run()
	{
		m_Func(m_lpParam);
	}
	
	OS_Task::~OS_Task()
	{
		delete m_task;
		m_task = 0;
	}

#endif


